//
//  AudioServiceManager.swift
//  SwiftProject
//
//  Created by qindong on 2021/8/30.
//  Copyright © 2021 qindong. All rights reserved.
//

import UIKit

class AudioServiceManager: NSObject {
    private var soundId : SystemSoundID = 1

    private override init() {
        super.init()
    }
    
    convenience init(_ resource : String, _ type : String) {
        self.init()
        // 获取音频文件
        let path = Bundle.main.path(forResource: resource, ofType: type)
        let soundUrl = URL(fileURLWithPath: path!)

        // 注册音效id
        AudioServicesCreateSystemSoundID(soundUrl as CFURL, &soundId)
    }

    /// 播放音效
    func playAudio() {
        AudioServicesPlaySystemSoundWithCompletion(soundId, nil)
    }
}

